package com.wxapp.system.service.controller;

import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.system.service.service.UploadService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author lgl
 * @Description 上传文件
 * @Datetime 2022/5/20 15:21
 * @Modified By
 */
@RequestMapping("file")
@RestController
@RequiredArgsConstructor
public class UploadController extends IBaseController {
    private final UploadService uploadService;

    @PostMapping(value = {"/upload/{path}","/upload"})
    @Operation(summary ="上传文件")
    public ResultVm<String> upload(@Schema(hidden = true) @User UserVo userVo, @RequestParam("file") MultipartFile file, @PathVariable(value = "path", required = false) String path) {
        return uploadService.upload(userVo, file, path);
    }

    @GetMapping("tempUrl/{name}")
    @Operation(summary ="得到临时url")
    public ResultVm<String> tempUrl(@PathVariable String name) throws Exception {
        return uploadService.tempUrl(name);
    }

    @DeleteMapping("/delFile/{name}")
    @Operation(summary ="得到临时url")
    public ResultVm<String> delFile(@PathVariable(value = "name") String name) {
        return uploadService.delFile(name);
    }
}